package ink.metoo.auto.fishpi.chatroom.command

import com.google.gson.Gson
import ink.metoo.auto.fishpi.Settings
import ink.metoo.auto.fishpi.call.ChatRoomCall
import ink.metoo.auto.fishpi.call.UserCall
import ink.metoo.auto.fishpi.chatroom.Message

class CamouflageMusicCommand : Command {

    private val gson = Gson()

    override val commandText: String = "/仿音乐"

    override fun isMatch(message: Message): Boolean {
        return super.isMatch(message) && message.isMe
    }

    override fun execute(message: Message) {
        val commandParams = message.commandParams
        val targetUsername = commandParams.getOrNull(1) ?: return
        val userAvatarURL = UserCall.getUserByName(targetUsername).userAvatarURL ?: return
        val content = mapOf(
            "coverURL" to userAvatarURL,
            "musicURL" to null,
            "msgType" to "music",
            "source" to Settings.fishpiClient.username + "#CamouflageMusicCommand",
            "title" to commandParams.subList(2, commandParams.size).joinToString(" "),
            "type" to "music"
        )
        ChatRoomCall.sendMessage("[music]" + gson.toJson(content) + "[/music]", false)
    }


}